/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.login.plugin.g;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.common.i.k;
import com.qihoo.gamecenter.sdk.common.i.s;
import com.qihoo.gamecenter.sdk.login.plugin.h.e;
import com.qihoo.gamecenter.sdk.login.plugin.h.f;
import com.qihoo.gamecenter.sdk.login.plugin.h.f.a;
import com.qihoo.gamecenter.sdk.login.plugin.h.h;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONObject;

public class n extends a {
    private String d = null;

    public n(Context paramContext, Intent paramIntent, String paramString) {
        super(paramContext, paramIntent);
        this.d = paramString;
    }

    protected String a(String[] paramArrayOfString) {
        com.qihoo.gamecenter.sdk.login.plugin.h.n localn = a(this.b, this.c, this.d);
        if ((localn != null) && (localn.b != null)) {
            localn.b = a(localn.b, this.d);
            try {
                JSONObject localJSONObject = new JSONObject();
                localJSONObject.put("error_code", 0);
                localJSONObject.put("error_msg", "ok");
                localJSONObject.put("content", localn.b);
                return localJSONObject.toString();
            } catch (Exception localException) {
                e.b("Login.SocialUserLoginTask", "doInBackground err", localException);
            }
        }
        return localn.a();
    }

    public static com.qihoo.gamecenter.sdk.login.plugin.h.n a(Context paramContext, Intent paramIntent,
            String paramString) {
        String str1 = "http://relation.gamebox.360.cn/9/user/login?";
        ArrayList localArrayList1 = new ArrayList();
        String str2 = s.r(paramContext);
        String str3 = f.c();
        localArrayList1.add(new f.a("appid", str2));
        localArrayList1.add(new f.a("nonce", str3));
        ArrayList localArrayList2 = new ArrayList();
        if (TextUtils.isEmpty(paramString)) {
            e.a("Login.SocialUserLoginTask", new Object[] { "fetch new access token!" });
            String str4 = "Qhopensdk-".concat(f.e());
            String str5 = k.a(com.qihoo.gamecenter.sdk.login.plugin.h.a.c(paramContext, null));
            String str6 = s.t(paramContext);
            String str7 = paramIntent.getStringExtra("login_type");
            str8 = str2;
            e.a("Login.SocialUserLoginTask", new Object[] { "ver = ", str4 });
            e.a("Login.SocialUserLoginTask", new Object[] { "mid = ", str5 });
            e.a("Login.SocialUserLoginTask", new Object[] { "channel", str6 });
            e.a("Login.SocialUserLoginTask", new Object[] { "login_type = ", str7 });
            e.a("Login.SocialUserLoginTask", new Object[] { "client_id = ", str8 });
            localArrayList2.add(new f.a("version", str4));
            localArrayList2.add(new f.a("mid", str5));
            localArrayList2.add(new f.a("DChannel", str6));
            localArrayList2.add(new f.a("oauth2_login_type", str7));
            localArrayList2.add(new f.a("client_id", str8));
        }
        else {
            e.a("Login.SocialUserLoginTask", new Object[] { "use local access_token = ", paramString });
            localArrayList2.add(new f.a("access_token", paramString));
        }
        long l1 = h.a(paramContext);
        long l2 = h.b(paramContext);
        String str8 = h.c(paramContext);
        e.a("Login.SocialUserLoginTask", new Object[] { "logincost = ", Long.valueOf(l1) });
        e.a("Login.SocialUserLoginTask", new Object[] { "regcost = ", Long.valueOf(l2) });
        e.a("Login.SocialUserLoginTask", new Object[] { "regtype = ", str8 });
        if (l1 > 0L)
            localArrayList2.add(new f.a("logincost", String.valueOf(l1)));
        if ((l2 > 0L) && (!(TextUtils.isEmpty(str8)))) {
            localArrayList2.add(new f.a("regcost", String.valueOf(l2)));
            localArrayList2.add(new f.a("regtype", str8));
        }
        String str9 = f.e();
        localArrayList2.add(new f.a("sdkver", str9));
        String str10 = f.a();
        str1 = f.a(str1, localArrayList1, localArrayList2, localArrayList2, str10);
        e.a("Login.SocialUserLoginTask", new Object[] { "appid=", str2 });
        e.a("Login.SocialUserLoginTask", new Object[] { "nonce=", str3 });
        e.a("Login.SocialUserLoginTask", new Object[] { "access_token=", paramString });
        e.a("Login.SocialUserLoginTask", new Object[] { "DesKey=", str10 });
        e.a("Login.SocialUserLoginTask", new Object[] { "sdkver = ", str9 });
        e.a("Login.SocialUserLoginTask", new Object[] { "url=", str1 });
        String str11 = com.qihoo.gamecenter.sdk.login.plugin.d.a.a(paramContext, str1);
        e.a("Login.SocialUserLoginTask", new Object[] { "server ret =", str11 });
        com.qihoo.gamecenter.sdk.login.plugin.h.n localn = f.a("Login.SocialUserLoginTask", paramContext, str11, str10,
                str1);
        return localn;
    }

    private JSONObject a(JSONObject paramJSONObject, String paramString) {
        if (null == paramJSONObject)
            return null;
        try {
            int i = paramJSONObject.optInt("errno", -1);
            if (0 == i) {
                JSONObject localJSONObject1 = new JSONObject();
                JSONObject localJSONObject2 = paramJSONObject.getJSONObject("data");
                JSONObject localJSONObject3 = localJSONObject2.getJSONObject("accessinfo");
                String str = localJSONObject3.optString("accessToken", "");
                if (TextUtils.isEmpty(str))
                    str = paramString;
                JSONObject localJSONObject4 = localJSONObject3.getJSONObject("token_info");
                long l = localJSONObject4.optLong("expires_in", 0L);
                localJSONObject1.put("access_token", str);
                localJSONObject1.put("expires_in", l);
                localJSONObject1.put("refresh_token", "");
                localJSONObject1.put("scope", "");
                localJSONObject1.put("user_login_res", paramJSONObject);
                return localJSONObject1;
            }
            return paramJSONObject;
        } catch (Exception localException) {
            e.b("Login.SocialUserLoginTask", "convertUserLoginJSONResult error!", localException);
        }
        return null;
    }
}